
(module
  one
  (import finalize)
  (include "glfw.sch")
  (include "gl.sch")
  (main main))

(define (s-quadric-finalizer obj)
   (gluDeleteQuadric (s-quadric-glu-quadric obj)))

(define (gen-s-quadric)
   (let
         ((val (instantiate::s-quadric)))
      (register-finalizer! s-quadric-finalizer val)
      val))

(define close #f)


(define
  (our-draw)
  (let ((t::double (glfwGetTime)))
     
     (glViewport 0 0 640 480)
     (glClearColor 0.0 0.0 0.0 0.0)
     (glClear (bit-or GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT))
     
     (glMatrixMode GL_PROJECTION)
     (glLoadIdentity)
     
     (gluPerspective
      65.0 ;;field of view
      (/ 640 480) ;; aspect ratio
      1.0 ;; near z clipping plane
      100.0 ;; far z clipping plane
      )
     
     (glMatrixMode GL_MODELVIEW)
     (glLoadIdentity)
     
     (gluLookAt
      0.0 0.0 10.0 ;;camera x,y,z 
      0.0 0.0 0.0  ;;view point x,y,z
      0.0 1.0 0.0  ;; up vector x,y,z
      )

     ;;rendering calls should go here
     
     ))

      
(define
  (our-loop)
  (do ((count 0 (+ 1 count)))
      (close 0)
      (begin (our-draw)
             (glfwSwapBuffers)
             (when (or (= (glfwGetWindowParam GLFW_OPENED) 0)
                       (= GLFW_PRESS (glfwGetKey GLFW_KEY_ESC)))
                   (set! close #t)))))
(define
  (main argc)
  (glfwInit)
  (glfwOpenWindow 640 480 8 8 8 8 24 0 GLFW_WINDOW)
  (glfwEnable GLFW_STICKY_KEYS)
  (our-loop)
  (glfwTerminate))
